﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL.RF.SourceCategory;
using Model.RF.SourceCategory;

namespace DAL.RF.SourceCategory
{
    public class NFCheck : BaseRepository_DT<NFCheckInfo>, INFCheck
    {
        #region 静态字段部分
        private const string PARM_NFCHECK_ID = "@ID";
        private const string PARM_NFCHECK_PRODUCTSN = "@ProductSN";
        private const string PARM_NFCHECK_RECORDTIME = "@RecordTime";
        private const string PARM_NFCHECK_PRODUCTTYPEID  = "@ProductTypeID";
        private const string PARM_NFCHECK_USERID = "@UserID";
        private const string PARM_NFCHECK_PCIP = "@PCIP";
        private const string PARM_NFCHECK_ISPASS = "@IsPass";
        #endregion

        #region 检索部分
        public int NFCheck_Insert(NFCheckInfo nfi)
        {
            SqlParameter[] Parms = GetParameters();
            SetParameters(nfi, Parms);
            SqlCommand cmd = new SqlCommand();
            foreach (SqlParameter parm in Parms)
                cmd.Parameters.Add(parm);
            using (SqlConnection conn = new SqlConnection(sqlHelper.ConnectionStringLocalTransaction))
            {
                conn.Open();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "NFCheck_Insert";
                int id = int.Parse(cmd.ExecuteScalar().ToString());
                return id;
            }
        }

        public IList<NFCheckInfo> LoadEntities()
        {
            return null;
        }

        public NFCheckInfo LoadEntity<T1>(T1 id)
        {
            SqlParameter parm=GetParameter();
            parm.Value = id;
            return ExcuteSqlToGetEntity("NFCheck_selectbyID", parm);
        } 

        public IList<NFCheckInfo> NFCheck_GetbyDT(DateTime startTime, DateTime stopTime)
        {
            SqlParameter[] parms = GetDTParameters();
            parms[0].Value = startTime;
            parms[1].Value = stopTime;
            return ExcuteSqlToGetEntities("NFCheck_selectbyDT", parms);
        }

        public IList<NFCheckInfo> NFCheck_GetbySN(string productSN)
        {
            SqlParameter parm = new SqlParameter(PARM_NFCHECK_PRODUCTSN, SqlDbType.NVarChar, 50);
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("NFCheck_selectbySN", parm);
        }
        #endregion

        #region 参数部分
        #endregion

        #region 重新基类部分
        public override NFCheckInfo GetEntityRecord(SqlDataReader rdr)
        {
            NFCheckInfo pro = new NFCheckInfo
            {
                ID = rdr.GetInt32(0),
                ProductSN = rdr.GetValue(1).ToString(),
                RecordTime = rdr.GetDateTime(2),
                ProductTypeID = rdr.GetValue(3).ToString(),
                UserID = rdr.GetValue(4).ToString(),
                PCIP = rdr.GetValue(5).ToString(),
                IsPass = rdr.GetBoolean(6)
            };
            return pro;
        }

        public override string GetInsertsp()
        {
            return base.GetInsertsp();
        }

        public override string GetUpdatesp()
        {
            return base.GetUpdatesp();
        }

        public override string GetDeletesp()
        {
            return base.GetDeletesp();
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_NFCHECK_ID, SqlDbType.Int, 4);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_NFCHECK_ID, SqlDbType.Int, 4),
					new SqlParameter(PARM_NFCHECK_PRODUCTSN, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_NFCHECK_RECORDTIME, SqlDbType.DateTime , 8),
					new SqlParameter(PARM_NFCHECK_PRODUCTTYPEID, SqlDbType.NVarChar , 50),
                    new SqlParameter(PARM_NFCHECK_USERID,SqlDbType.NVarChar,10),
                    new SqlParameter(PARM_NFCHECK_PCIP,SqlDbType.NVarChar,20),
                    new SqlParameter(PARM_NFCHECK_ISPASS,SqlDbType.Bit,1)
                };
            return parms;
        }

        public override void SetParameters(NFCheckInfo tci, params SqlParameter[] Parms)
        {
            Parms[0].Value = tci.ID;
            Parms[1].Value = tci.ProductSN;
            Parms[2].Value = tci.RecordTime;
            Parms[3].Value = tci.ProductTypeID;
            Parms[4].Value = tci.UserID;
            Parms[5].Value = tci.PCIP;
            Parms[6].Value = tci.IsPass;
        }
        #endregion
    }
}
